package constants

import (
	"os"
	"runtime"
	"time"
)

const (
	ScaleJobAppLabel = "cke-scale-nodes-job"
	DownJobAppLabel  = "cke-down-nodes-job"

	ComplatedStatus = "Complated"
	RunningStatus   = "Running"
	FailedStatus    = "Failed"
)

const (
	// deprecated, use PatchFileTag replace
	PatchNameTag          = "yaml"
	PatchFileTag          = "y*ml"
	AnnotationLengthLimit = 63
	CkeDeployConfigPath   = "/opt/ckeadm"

	CkeDeployContainerName = "ckeadm-create-container"

	// Ansible log level: 1, 2 OR 3
	AnsibleLogLevel = 2

	// ModeRBAC is the mode to use Role Based Access Control to authorize
	AnsiblePlaybookCommand = "ansible-playbook"
	// ModeNode is an authorization mode that authorizes API requests made by kubelets.
	AnsibleConfig = KubeDeployDir + "/my_inventory/my_inventory.cfg"
	// ansible all yml config
	AnsibleAllConfig = KubeDeployDir + "/my_inventory/group_vars/all.yml"
	// APICallRetryInterval defines how long kubeadm should wait before retrying a failed API operation
	AnsibleLogDir = "/var/log/ckectl"
	// ModeRBAC is the mode to use Role Based Access Control to authorize
	KubeDeployDir = "/opt/kubernetes-deploy"

	// TLSBootstrapTimeout specifies how long kubeadm should wait for the kubelet to perform
	AnsibleTimeOut = "600"

	CkectlContainerName = "cke-deploy-runner"

	WhichCkectl = "/usr/local/bin/ckectl"

	WaitCallRetryInterval = 500 * time.Millisecond

	WaitRestartTimeout = 1 * time.Minute

	CkectlUpPhaseNum = 27

	ClusterConfigDefault = "cluster.yml"

	SourcesFile = "sources.yml"

	CkeadmWatchServiceName = "ckeadm-wait"

	WhichCkeadm = "/usr/local/bin/ckeadm"

	ClusterIdDefault = "unknow_cluster_id"

	CkeadmWaitInfoPattern = "/info"

	CkeadmWaitProgressPattern = "/progress/"

	CkeadmWaitHealthzPattern = "/healthz"

	// ansible done files
	AnsibleUpDoneFile        = "up.done"
	AnsibleScaleDownDoneFile = "scale.down.done"
	AnsibleScaleDoneFile     = "scale.done"
	AnsibleUpdateDoneFile    = "update.done"

	CkeadmLogCacheDir = "/var/log/ckeadm"

	EmptyString = ""
	WaitPort    = 2376

	SourceContainerPath = "/opt/ckectl/sources.yml"

	CKEncode = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

	AddonsAnnotationsName = "ckev4/addons"
)

var (
	archs = map[string]string{
		"arm64":    "arm64",
		"amd64":    "amd64",
		"mips64el": "mips64el",
		"mips64le": "mips64el",
	}

	ARCH = archs[runtime.GOARCH]
)

var (
	AnsibleImageRepo = "library/cke/cke-deploy-v4"
	ForkThreads      = 5
	CkeNodeForks     = 500
	CkeadmOverwrite  = true

	Debug = func() bool {
		if "true" == os.Getenv("CkeadmDebug") {
			return true
		}
		return false
	}()
)
